package com.yj.string;

/**
 * 写出一个程序，接受一个字符串，然后输出该字符串反转后的字符串。（字符串长度不超过1000）
 */
public class Solution02 {
    public static void main(String[] args) {
        String s = solve2("abcd");
        System.out.println(s);
    }

    private static String solve(String s) {
        if (s.length()>1000){
            return "字符串超过长度限制！";
        }


        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length ; i++) {
            chars[i] = s.charAt(s.length()-1-i);
        }
        return new String(chars);
    }

    private static String solve2(String s) {
        if (s.length()>1000){
            return "字符串超过长度限制！";
        }


        char[] chars = s.toCharArray();
        for (int i = 0; i < s.length()/2 ; i++) {
            int temp = chars[i];
            chars[i] = chars[s.length()-i-1];
            chars[s.length()-i-1] = (char) temp;
        }
        return new String(chars);
    }
}
